#include "maganeticsensortest.h"
#include "ui_maganeticsensortest.h"
#include <QDebug>
#include "rfidsensor.h"

MaganeticSensorTest::MaganeticSensorTest(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MaganeticSensorTest)
{
    ui->setupUi(this);
    maganeticSensor = new MaganeticSensor("/tcrwork/linuxController/trunk/TcrController/data/globalConfig/maganeticSensor/maganeticSensor.xml");
}

MaganeticSensorTest::~MaganeticSensorTest()
{
    delete ui;
}

void MaganeticSensorTest::on_Button_DeviceId_clicked()
{
    int deviceId = ui->Edit_DeviceId->text().toInt();
    double positionOut;
    int resultKey = maganeticSensor->getSensorPositionValue(deviceId, positionOut);
    ui->Edit_SensorTempture->setText(QString("%1").arg(resultKey));
    ui->Edit_Position->setText((QString("%1").arg(positionOut)));

}

void MaganeticSensorTest::on_Button_SetAddress_clicked()
{
    int primaryId = ui->Edit_PrimaryAddress->text().toInt();
    int targetId = ui->Edit_TargetAddress->text().toInt();
    qDebug() << "The PrimaryId:" << primaryId;
    qDebug() << "The TargetId:" << targetId;
    int resultKey = maganeticSensor->setSensorDeviceId(primaryId, targetId);
    ui->Edit_SensorTempture->setText(QString("%1").arg(resultKey));
    if(  resultKey == 1)
    {
        qDebug() << "The Address updated success!";
    }
    else
    {
         qDebug() << "The Address updated failed!";
    }

}

void MaganeticSensorTest::on_pushButton_clicked()
{
    RfidSensor rfidSensor("/tcrwork/linuxController/trunk/TcrController/data/globalConfig/rfidSensor.xml");
    int deviceId = ui->Edit_RFID_DeviceId->text().toInt();
    double value;
    int resultKey = rfidSensor.getCurrentTagData(deviceId, value);
    if(resultKey != 1)
    {
        ui->pushButton->setText("数据获取失败!");
        ui->Edit_TagData->setText(QString("%1").arg(value));
    }
    else
    {
        ui->pushButton->setText("数据获取成功!");
        ui->Edit_TagData->setText(QString("%1").arg(value));
    }

}
